﻿using ControlzEx.Standard;
using GpCommon;
using GpCommon.Helpers;
using GpCommon.Models;
using GPSpeedView.Models;
using HtmlAgilityPack;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Reflection.Emit;
using System.Security.Policy;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace GPSpeedView.GPHelpers
{
    public class AlGpHelper
    {
        /// <summary>
        /// 是否有高概率
        /// 规则： 20个交易日内无涨停(涨幅超过7个点)，无明显振幅（暂定振幅超7个点）,涨幅均值在正负4-5个点区间
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static bool HasHighChance(string code,List<GpDayEntity> ents = null)
        {
            if(ents == null)
            {
                ents = GpNetDataHelper.GetHistoryDayInfoByCode(code).Result;
                if (ents.Count == 0) return false;
            }

            if (ents.Count < 30)
                return false;
            // 获取最近20个交易日数据
            var last20Info = ents.GetRange(ents.Count - 20, 20);

            if (last20Info.Find(x => x.MarkUp >= 5) != null
                || last20Info.Find(x => x.MarkUp <= -5) != null)
                return false;
            //if (last20Info.Find(x => x.Amplitude >= 7) != null)
            //    return false;
            double tempTotalMarkUp = 0;
            last20Info.ForEach(x => tempTotalMarkUp += x.MarkUp);
            if(Math.Abs(tempTotalMarkUp / 20.0) >= 5)
                return false;
            return true;
        }
        public static bool HasHighChance2(string code,DateTime time,bool isCheckPre,out GpDayEntity todayEnt)
        {
            todayEnt = null;
            bool result = false;
            var list = GpLocalDataHelper.GetLocalHistoryDayInfoByCode(2023, code);
            if (list == null || list.Count < 10) return result;
            var maxPrice = list.Max(x => x.ClsPrice);
            var minPrice = list.Min(x => x.ClsPrice);
            var midPrice = (maxPrice - minPrice) * 0.5 + minPrice;

            int index = list.FindIndex(x => x.Time.Month == time.Month && x.Time.Day == time.Day);
            if (index < 10) return result;
            //if (curPrice >= midPrice) return result;
            //if (curMarkUp <= 5) return result;
            todayEnt = list[index];
            if (isCheckPre == true)
            {
                if (list[index].PrePrice <= list[index - 1].ClsPrice * 1.03)
                    return result;
            }
            else if(isCheckPre == false)
            {
                if (list[index].ClsPrice <= list[index - 1].ClsPrice * 1.03)
                    return result;
            }
            int highCount = 0;
            bool isSucc = true;
            for (int i = 1; i < 11; i++)
            {
                if (list[index - i].MarkUp >= 5 || list[index - i].MarkUp <= -5)
                {
                    highCount++;
                }
                if (list[index - i].HighPrice > list[index - i - 1].ClsPrice * 1.06
                    || list[index - i].HighPrice - list[index - i].LowPrice > list[index - i - 1].ClsPrice * 0.06)
                {
                    highCount++;
                }
                if (highCount > 1)
                {
                    isSucc = false;
                    break;
                }
            }
            if (!isSucc) return result;

            //if (list[index - 1].ClsPrice < list[index - 10].ClsPrice * 0.98) continue;
            //if (list[index - 1].ClsPrice < list[index - 5].ClsPrice * 0.98) continue;
            return true;
        }
        public static bool HasHighChance2(string code, DateTime time)
        {
            bool result = false;
            var list = GpLocalDataHelper.GetLocalHistoryDayInfoByCode(2023, code);
            if (list == null || list.Count < 10) return result;
            var maxPrice = list.Max(x => x.ClsPrice);
            var minPrice = list.Min(x => x.ClsPrice);
            var midPrice = (maxPrice - minPrice) * 0.5 + minPrice;

            int index = list.FindIndex(x => x.Time.Month == time.Month && x.Time.Day == time.Day);
            if (index < 10) return result;
            //if (curPrice >= midPrice) return result;
            //if (curMarkUp <= 5) return result;

            int highCount = 0;
            bool isSucc = true;
            for (int i = 1; i < 11; i++)
            {
                if (list[index - i].MarkUp >= 5 || list[index - i].MarkUp <= -5)
                {
                    highCount++;
                }
                if (list[index - i].HighPrice > list[index - i - 1].ClsPrice * 1.06
                    || list[index - i].HighPrice - list[index - i].LowPrice > list[index - i - 1].ClsPrice * 0.06)
                {
                    highCount++;
                }
                if (highCount > 1)
                {
                    isSucc = false;
                    break;
                }
            }
            if (!isSucc) return result;

            //if (list[index - 1].ClsPrice < list[index - 10].ClsPrice * 0.98) continue;
            //if (list[index - 1].ClsPrice < list[index - 5].ClsPrice * 0.98) continue;
            return true;
        }
        public static bool HasHighChance2(string code, float curPrice = 0, float curMarkUp = 0)
        {
            bool result = false;
            var list = GpLocalDataHelper.GetLocalHistoryDayInfoByCode(2023, code);
            if (list == null || list.Count < 10) return result;
            var maxPrice = list.Max(x => x.ClsPrice);
            var minPrice = list.Min(x => x.ClsPrice);
            var midPrice = (maxPrice - minPrice) * 0.5 + minPrice;

            DateTime time = DateTime.Now;
            int index = list.FindIndex(x => x.Time.Month == time.Month && x.Time.Day == time.Day);
            if (index < 10)
            {
                index = list.Count;
            }
            if (index < 10) return result;
            //if (curPrice >= midPrice) return result;
            //if (curMarkUp <= 5) return result;

            int highCount = 0;
            bool isSucc = true;
            for (int i = 1; i < 11; i++)
            {
                if (list[index - i].MarkUp >= 5 || list[index - i].MarkUp <= -5)
                {
                    highCount++;
                }
                if (list[index - i].HighPrice > list[index - i - 1].ClsPrice * 1.06
                    || list[index - i].HighPrice - list[index - i].LowPrice > list[index - i - 1].ClsPrice * 0.06)
                {
                    highCount++;
                }
                if (highCount > 1)
                {
                    isSucc = false;
                    break;
                }
            }
            if (!isSucc) return result;

            //if (list[index - 1].ClsPrice < list[index - 10].ClsPrice * 0.98) continue;
            //if (list[index - 1].ClsPrice < list[index - 5].ClsPrice * 0.98) continue;
            return true;
        }
        /// <summary>
        ///  获取上次机会首板日期
        /// </summary>
        /// <returns></returns>
        public static DateTime GetLastHighChanceFirstTop(string code)
        {
            var ents = GpNetDataHelper.GetHistoryDayInfoByCode(code).Result;

            int index = ents.FindLastIndex(x => x.MarkUp >= 7);
            while (index >= 0)
            {
                var tempList = ents.GetRange(0, index);
                if (HasHighChance(code, tempList))
                    return ents[index].Time;
                index = tempList.FindLastIndex(x => x.MarkUp >= 7);
            }
            return DateTime.MinValue;
        }




        public static int HistoryGpNum;
        public static string InfoMsg;
        /// <summary>
        /// 加载历史日线数据
        /// </summary>
        /// <param name="worker"></param>
        public static void LoadHistoryGpInfo(BackgroundWorker worker)
        {
            InfoMsg = "历史日线数据加载";
            string rootPath = CommonData.HisInfoFolderPath;
            try
            {
                if (!Directory.Exists(rootPath))
                {
                    Directory.CreateDirectory(rootPath);
                }
                int startYear = 1990; // 从1990开始
                while (startYear <= DateTime.Now.Year)
                {
                    if(!Directory.Exists(rootPath + "\\" + startYear))
                        Directory.CreateDirectory(rootPath + "\\" + startYear);
                    startYear++;
                }
                var codes = GpLocalDataHelper.GetValidGpCodes();
                HistoryGpNum = codes.Count;
                int index = 0;
                ParallelOptions options = new ParallelOptions();
                options.MaxDegreeOfParallelism = 10;
                Parallel.ForEach(codes, options,
                    item =>
                    {
                        bool hasEx = false;
                        List<GpDayEntity> list = null;
                        do
                        {
                            try
                            {
                                list = GpNetDataHelper.GetHistoryDayInfoByCode(item).Result;
                                hasEx = false;
                            }
                            catch (AggregateException)
                            {
                                hasEx = true;
                            }
                        } while (hasEx);


                        Dictionary<int, List<GpDayEntity>> dic = new Dictionary<int, List<GpDayEntity>>();

                        foreach (var day in list)
                        {
                            if (dic.ContainsKey(day.Time.Year))
                            {
                                dic[day.Time.Year].Add(day);
                            }
                            else
                            {
                                dic.Add(day.Time.Year, new List<GpDayEntity> { day });
                            }
                        }

                        foreach (var keyValue in dic)
                        {
                            var filePath = Path.Combine(rootPath, keyValue.Key.ToString(), keyValue.Value[0].Code + ".json");
                            //if (File.Exists(filePath)) continue;

                            StringBuilder stringBuilder = new StringBuilder();
                            foreach (var sub in keyValue.Value)
                            {
                                stringBuilder.Append(sub.ToString() + ";");
                            }
                            if (stringBuilder.Length == 0) continue;

                            File.WriteAllText(filePath, stringBuilder.ToString());
                        }
                        index++;
                        worker.ReportProgress(index * 100 / codes.Count, index);
                    });
                #region 旧
                //foreach (var item in codes)
                //{
                //    bool hasEx = false;
                //    List<GpDayEntity> list = null;
                //    do
                //    {
                //        try
                //        {
                //            list = GetHistoryDayInfoByCode(item).Result;
                //            hasEx = false;
                //        }
                //        catch (AggregateException)
                //        {
                //            hasEx = true;
                //        }
                //    } while (hasEx);


                //    Dictionary<int, List<GpDayEntity>> dic = new Dictionary<int, List<GpDayEntity>>();

                //    foreach (var day in list)
                //    {
                //        if (dic.ContainsKey(day.Time.Year))
                //        {
                //            dic[day.Time.Year].Add(day);
                //        }
                //        else
                //        {
                //            dic.Add(day.Time.Year, new List<GpDayEntity> { day });
                //        }
                //    }

                //    foreach (var keyValue in dic)
                //    {
                //        var filePath = Path.Combine(rootPath, keyValue.Key.ToString(), keyValue.Value[0].Code + ".json");
                //        if (File.Exists(filePath)) continue;

                //        StringBuilder stringBuilder = new StringBuilder();
                //        foreach (var sub in keyValue.Value)
                //        {
                //            stringBuilder.Append(sub.ToString() + ";");
                //        }
                //        if (stringBuilder.Length == 0) continue;

                //        File.WriteAllText(filePath, stringBuilder.ToString());
                //    }

                //    int i = codes.IndexOf(item);
                //    worker.ReportProgress((i + 1) * 100 / codes.Count,i + 1);
                //}
                #endregion
            }
            catch (Exception)
            {
                return;
            }

            MessageBox.Show($"{InfoMsg}完成");
        }

        ///// <summary>
        ///// 加载历史五分分时数据
        ///// </summary>
        ///// <param name="worker"></param>
        ///// <returns></returns>
        //public static bool LoadHistoryMS5Info(BackgroundWorker worker = null)
        //{
        //    InfoMsg = "历史分时数据加载";

        //    string rootPath = ConfigData.HisMS5InfoFolderPath;
        //    if (!Directory.Exists(rootPath))
        //        return false;
        //    var files = Directory.GetFiles(rootPath);
        //    HistoryGpNum = files.Length;

        //    int index = 0;
        //    try
        //    {
        //        ParallelOptions options = new ParallelOptions();
        //        options.MaxDegreeOfParallelism = 10;
        //        Parallel.ForEach(files, options,
        //            file => 
        //            {
        //                string code = file.Substring(file.Length - 10, 6);
        //                using (FileStream stream = File.OpenRead(file))
        //                {
        //                    while (true)
        //                    {
        //                        try
        //                        {
        //                            byte[] buffer = new byte[32];
        //                            int bufferCount = stream.Read(buffer, 0, 32);
        //                            if (bufferCount <= 0) break;
        //                            GpDayMSEntity ent = GpDayMSEntity.Create(code, buffer);
        //                            if (ent == null) continue;
        //                            if (ConfigData.History5MSInfo.ContainsKey(code))
        //                            {
        //                                if (ConfigData.History5MSInfo[code].Find(x => x.CurTime == ent.CurTime) == null)
        //                                    ConfigData.History5MSInfo[code].Add(ent);
        //                            }
        //                            else
        //                            {
        //                                ConfigData.History5MSInfo.TryAdd(code, new List<GpDayMSEntity> { ent });
        //                            }
        //                        }
        //                        catch (Exception ex)
        //                        {
        //                            break;
        //                        }
        //                    }
        //                }
        //                index++;
        //                if (worker != null)
        //                    worker.ReportProgress(index * 100 / HistoryGpNum, index);
        //            });
        //        #region 旧
        //        //foreach (var file in files)
        //        //{
        //        //    string code = file.Substring(file.Length - 10, 6);
        //        //    using (FileStream stream = File.OpenRead(file))
        //        //    {
        //        //        while (true)
        //        //        {
        //        //            try
        //        //            {
        //        //                byte[] buffer = new byte[32];
        //        //                int bufferCount = stream.Read(buffer, 0, 32);
        //        //                if (bufferCount <= 0) break;
        //        //                GpDayMSEntity ent = GpDayMSEntity.Create(code, buffer);
        //        //                if (ent == null) continue;
        //        //                if (ConfigData.History5MSInfo.ContainsKey(code))
        //        //                {
        //        //                    if (ConfigData.History5MSInfo[code].Find(x => x.CurTime == ent.CurTime) == null)
        //        //                        ConfigData.History5MSInfo[code].Add(ent);
        //        //                }
        //        //                else
        //        //                {
        //        //                    ConfigData.History5MSInfo.Add(code, new List<GpDayMSEntity> { ent });
        //        //                }
        //        //            }
        //        //            catch (Exception ex)
        //        //            {
        //        //                break;
        //        //            }
        //        //        }
        //        //    }
        //        //    index++;
        //        //    if (worker != null)
        //        //        worker.ReportProgress(index * 100 / HistoryGpNum, index);
        //        //}
        //        #endregion
        //    }
        //    catch (Exception ex)
        //    {
        //        MessageBox.Show(ex.Message);
        //        if (worker != null)
        //            worker.ReportProgress(100, index);
        //        return false;
        //    }

        //    return true;
        //}
        /// <summary>
        /// 导入历史5分分时数据
        /// </summary>
        /// <param name="files"></param>
        /// <returns></returns>
        public static bool ImportHistory5MSInfo(List<string> files, BackgroundWorker worker)
        {
            InfoMsg = "历史5分分时数据导入";
            files.RemoveAll(x => !x.Contains("sz00") && !x.Contains("sz30") && !x.Contains("sh60"));
            HistoryGpNum = files.Count;
            string rootPath = CommonData.His5MSInfoFolderPath;
            if (!Directory.Exists(rootPath))
            {
                Directory.CreateDirectory(rootPath);
            }
            int startYear = 1990;
            while (startYear <= DateTime.Now.Year)
            {
                var tempPath = Path.Combine(rootPath, startYear.ToString());
                if (!Directory.Exists(tempPath))
                {
                    Directory.CreateDirectory(tempPath);
                }
                startYear++;
            }
            var codes = GpLocalDataHelper.GetValidGpCodes();
            if (codes == null || codes.Count == 0) return false;

            int index = 0;

            try
            {
                ParallelOptions options = new ParallelOptions();
                options.MaxDegreeOfParallelism = 10;
                Parallel.ForEach(files, options,
                    file =>
                    {
                        try
                        {
                            string code = file.Substring(file.Length - 10, 6);
                            if (codes.Contains(code))
                            {
                                var localFiles = Directory.GetFiles(rootPath, $"{code}.txt", SearchOption.AllDirectories);
                                List<GpDayMSEntity> totalEnts = new List<GpDayMSEntity>();
                                foreach (var localFile in localFiles)
                                {
                                    using (FileStream stream = File.OpenRead(localFile))
                                    {
                                        while (true)
                                        {
                                            try
                                            {
                                                byte[] buffer = new byte[32];
                                                int bufferCount = stream.Read(buffer, 0, 32);
                                                if (bufferCount <= 0) break;
                                                GpDayMSEntity ent = GpDayMSEntity.Create(code, buffer);
                                                if (ent == null) continue;
                                                totalEnts.Add(ent);
                                            }
                                            catch (Exception ex)
                                            {
                                                break;
                                            }
                                        }
                                    }
                                }
                                using (FileStream stream = File.OpenRead(file))
                                {
                                    while (true)
                                    {
                                        try
                                        {
                                            byte[] buffer = new byte[32];
                                            int bufferCount = stream.Read(buffer, 0, 32);
                                            if (bufferCount <= 0) break;
                                            GpDayMSEntity ent = GpDayMSEntity.Create(code, buffer);
                                            if (ent == null) continue;
                                            var tempEnt = totalEnts.Find(x => x.CurTime == ent.CurTime);
                                            if (tempEnt != null)
                                                totalEnts.Remove(tempEnt);
                                            totalEnts.Add(ent);
                                        }
                                        catch (Exception ex)
                                        {
                                            break;
                                        }
                                    }
                                }
                                var groupList = totalEnts.GroupBy(x => x.CurTime.Year);
                                foreach (var item in groupList)
                                {
                                    string filePath = Path.Combine(rootPath, item.Key.ToString(), code + ".txt");
                                    List<byte> writeBytes = new List<byte>();
                                    foreach (var gpEnt in item)
                                    {
                                        writeBytes.AddRange(gpEnt.GetBytes());
                                    }
                                    File.WriteAllBytes(filePath, writeBytes.ToArray());
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message,"并发中报错");
                        }

                        index++;
                        worker.ReportProgress(index * 100 / HistoryGpNum, index);
                    });
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                worker.ReportProgress(100, index);
                return false;
            }

            MessageBox.Show($"{InfoMsg}完成");

            return true;

        }

        /// <summary>
        /// 导入历史1分分时数据
        /// </summary>
        /// <param name="files"></param>
        /// <returns></returns>
        public static bool ImportHistory1MSInfo(List<string> files, BackgroundWorker worker)
        {
            InfoMsg = "历史1分分时数据导入";
            files.RemoveAll(x => !x.Contains("sz00") && !x.Contains("sz30") && !x.Contains("sh60"));
            HistoryGpNum = files.Count;
            string rootPath = CommonData.His1MSInfoFolderPath;
            if (!Directory.Exists(rootPath))
            {
                Directory.CreateDirectory(rootPath);
            }
            int startYear = 1990;
            while (startYear <= DateTime.Now.Year)
            {
                var tempPath = Path.Combine(rootPath, startYear.ToString());
                if (!Directory.Exists(tempPath))
                {
                    Directory.CreateDirectory(tempPath);
                }
                startYear++;
            }
            var codes = GpLocalDataHelper.GetValidGpCodes();
            if (codes == null || codes.Count == 0) return false;

            int index = 0;

            try
            {
                ParallelOptions options = new ParallelOptions();
                options.MaxDegreeOfParallelism = 10;
                Parallel.ForEach(files, options,
                    file =>
                    {
                        try
                        {
                            string code = file.Substring(file.Length - 10, 6);
                            if (codes.Contains(code))
                            {
                                var localFiles = Directory.GetFiles(rootPath, $"{code}.txt", SearchOption.AllDirectories);
                                List<GpDayMSEntity> totalEnts = new List<GpDayMSEntity>();
                                foreach (var localFile in localFiles)
                                {
                                    using (FileStream stream = File.OpenRead(localFile))
                                    {
                                        while (true)
                                        {
                                            try
                                            {
                                                byte[] buffer = new byte[32];
                                                int bufferCount = stream.Read(buffer, 0, 32);
                                                if (bufferCount <= 0) break;
                                                GpDayMSEntity ent = GpDayMSEntity.Create(code, buffer);
                                                if (ent == null) continue;
                                                totalEnts.Add(ent);
                                            }
                                            catch (Exception ex)
                                            {
                                                break;
                                            }
                                        }
                                    }
                                }
                                using (FileStream stream = File.OpenRead(file))
                                {
                                    while (true)
                                    {
                                        try
                                        {
                                            byte[] buffer = new byte[32];
                                            int bufferCount = stream.Read(buffer, 0, 32);
                                            if (bufferCount <= 0) break;
                                            GpDayMSEntity ent = GpDayMSEntity.Create(code, buffer);
                                            if (ent == null) continue;
                                            var tempEnt = totalEnts.Find(x => x.CurTime == ent.CurTime);
                                            if (tempEnt != null)
                                                totalEnts.Remove(tempEnt);
                                            totalEnts.Add(ent);
                                        }
                                        catch (Exception ex)
                                        {
                                            break;
                                        }
                                    }
                                }
                                var groupList = totalEnts.GroupBy(x => x.CurTime.Year);
                                foreach (var item in groupList)
                                {
                                    string filePath = Path.Combine(rootPath, item.Key.ToString(), code + ".txt");
                                    List<byte> writeBytes = new List<byte>();
                                    foreach (var gpEnt in item)
                                    {
                                        writeBytes.AddRange(gpEnt.GetBytes());
                                    }
                                    File.WriteAllBytes(filePath, writeBytes.ToArray());
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "并发中报错");
                        }

                        index++;
                        worker.ReportProgress(index * 100 / HistoryGpNum, index);
                    });
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                worker.ReportProgress(100, index);
                return false;
            }

            MessageBox.Show($"{InfoMsg}完成");

            return true;

        }

        public static void GetGoUpTMostGPs(BackgroundWorker worker)
        {
            AlGpHelper.InfoMsg = "获取指定数据";
            var codes = GpLocalDataHelper.GetValidGpCodes();
            int topTotal = 0;
            int topMost = 0;
            AlGpHelper.HistoryGpNum = codes.Count;
            int index = 0;
            foreach (var code in codes)
            {
                Thread.Sleep(500);
                var list = GpNetDataHelper.GetGpDetail(code).Result;
                TimeSpan start = new TimeSpan(9, 40, 0);
                TimeSpan end = new TimeSpan(11, 0, 0);
                var startEnt = list.Find(x => x.EntTimeSpan.TimeOfDay == start);
                var endEnt = list.Find(x => x.EntTimeSpan.TimeOfDay == end);
                if(startEnt != null && endEnt != null && startEnt.MarkUp <= 9.5 && endEnt.MarkUp <= 9.5)
                {
                    int startIndex = list.IndexOf(startEnt);
                    int endIndex = list.IndexOf(endEnt);
                    bool hasDown = false;
                    for (int i = startIndex; i < endIndex + 1; i++)
                    {
                        if(list[i].MidPrice > list[i].Price)
                        {
                            hasDown = true;
                            break;
                        }
                    }
                    if (!hasDown)
                    {
                        MessageBox.Show(code);
                    }
                }
                index++;
                worker.ReportProgress(index * 100 / codes.Count, index);
            }
        }


        /// <summary>
        /// 指定时间是否是上升趋势
        /// 多头上升，均线上升或者均线水平（前期为下降趋势）
        /// </summary>
        /// <param name="code"></param>
        /// <param name="targetTime"></param>
        /// <returns></returns>
        public static bool IsGoUpTendency(string code,DateTime targetTime)
        {
            var dayInfo = GpLocalDataHelper.GetLocalHistoryDayInfoByCode(targetTime.Year, code);
            // 5,10， 20 为上升
            int index = dayInfo.FindIndex(x => x.Time == targetTime);
            if(index >= 5)
            {
                if (dayInfo[index].Day5Price >= dayInfo[index - 5].Day5Price
                    && dayInfo[index].Day10Price >= dayInfo[index - 5].Day10Price
                    && dayInfo[index].Day20Price >= dayInfo[index - 5].Day20Price)
                    return true;
            }
            return false;
        }
        public static bool HasFastMarkUp(DateTime time,string code,out DateTime markUpTime)
        {
            markUpTime = DateTime.MinValue;
            var ms1Ents = GpLocalDataHelper.GetDay1MSEntitiesByCode(time.Year, code);
            var ms1DayEnts = ms1Ents.FindAll(x => x.CurTime.Month == time.Month && x.CurTime.Day == time.Day);
            if (ms1DayEnts.Count <= 0) return false;
            var sortedList =  ms1DayEnts.OrderBy(x => x.CurTime).ToList();
            int index = ms1Ents.FindIndex(x => x == sortedList[0]);
            if(index<= 0) return false;
            var clsPrice = ms1Ents[index - 1].EndPrice;
            for (int i = 1; i < sortedList.Count(); i++)
            {
                if (sortedList[i].EndPrice - sortedList[i - 1].EndPrice >= clsPrice * 0.02)
                {
                    markUpTime = sortedList[i].CurTime;
                    return true;
                }
            }
            return false;
        }


    }
}
